<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@page import="java.util.UUID"%>
<%@page import="java.security.interfaces.RSAPublicKey"%>
<%@page import="org.apache.commons.lang.ArrayUtils"%>
<%@page import="org.apache.commons.codec.binary.Base64"%>
<%@page import="org.apache.shiro.web.filter.authc.FormAuthenticationFilter"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="com.finalist.Setting"%>
<%@page import="com.finalist.util.SettingUtils"%>
<%@page import="com.finalist.util.SpringUtils"%>
<%@page import="com.finalist.Setting.CaptchaType"%>
<%@page import="com.finalist.Setting.AccountLockType"%>
<%@page import="com.finalist.service.RSAService"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
String base = request.getContextPath();
String captchaId = UUID.randomUUID().toString();
ApplicationContext applicationContext = SpringUtils.getApplicationContext();
Setting setting = SettingUtils.get();
if (applicationContext != null) {
%>
<shiro:authenticated>
<%
response.sendRedirect(base + "/admin/common/main.jhtml");
%>
</shiro:authenticated>
<%
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script type="text/javascript">
	var points = [ (window.performance && window.performance.timing && window.performance.timing.navigationStart)
			|| +new Date() ];
</script>
<meta name="baidu-site-verification" content="DLH0DxvBfi">
<title>风客主题旅行</title>
<meta name="keywords" content="">
<link href="<%=base%>/favicon.ico" rel="Shortcut Icon">
<link onerror="wx_loaderror(this)" rel="stylesheet"
	href="<%=base%>/resources/travel/pc/css/fk_login.css">
<script type="text/javascript">
	points[1] = +new Date() - points[0];//css加载完成
</script>
<script src="<%=base%>/resources/weixin/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript"
	src="<%=base%>/resources/admin/js/jquery.validate.js?n=1"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<%
if (applicationContext != null) {
	RSAService rsaService = SpringUtils.getBean("rsaServiceImpl", RSAService.class);
	RSAPublicKey publicKey = rsaService.generateKey(request);
	String modulus = Base64.encodeBase64String(publicKey.getModulus().toByteArray());
	String exponent = Base64.encodeBase64String(publicKey.getPublicExponent().toByteArray());
	
	String message = null;
	String loginFailure = (String) request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
	if (loginFailure != null) {
		if (loginFailure.equals("org.apache.shiro.authc.pam.UnsupportedTokenException")) {
			message = "admin.captcha.invalid";
		} else if (loginFailure.equals("org.apache.shiro.authc.UnknownAccountException")) {
			message = "admin.login.unknownAccount";
		} else if (loginFailure.equals("org.apache.shiro.authc.DisabledAccountException")) {
			message = "admin.login.disabledAccount";
		} else if (loginFailure.equals("org.apache.shiro.authc.LockedAccountException")) {
			message = "admin.login.lockedAccount";
		} else if (loginFailure.equals("org.apache.shiro.authc.IncorrectCredentialsException")) {
			if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) {
				message = "admin.login.accountLockCount";
			} else {
				message = "admin.login.incorrectCredentials";
			}
		} else if (loginFailure.equals("org.apache.shiro.authc.AuthenticationException")) {
			message = "admin.login.authentication";
		}
	}
%>
<title><%=SpringUtils.getMessage("admin.login.title")%> - Powered By SHOP++</title>
<meta http-equiv="expires" content="0" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta name="author" content="Finalist IT Group" />
<meta name="copyright" content="SHOP++" />
<link href="<%=base%>/resources/admin/css/common.css" rel="stylesheet" type="text/css" />
<link href="<%=base%>/resources/admin/css/login.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=base%>/resources/admin/js/jquery.js"></script>
<script type="text/javascript" src="<%=base%>/resources/admin/js/jsbn.js"></script>
<script type="text/javascript" src="<%=base%>/resources/admin/js/prng4.js"></script>
<script type="text/javascript" src="<%=base%>/resources/admin/js/rng.js"></script>
<script type="text/javascript" src="<%=base%>/resources/admin/js/rsa.js"></script>
<script type="text/javascript" src="<%=base%>/resources/admin/js/base64.js"></script>
<script type="text/javascript" src="<%=base%>/resources/admin/js/common.js"></script>
<script type="text/javascript">
	$().ready( function() {
		
		var $loginForm = $("#loginForm");
		var $enPassword = $("#enPassword");
		var $username = $("#username");
		var $password = $("#password");
		var $captcha = $("#captcha");
		var $captchaImage = $("#captchaImage");
		var $isRememberUsername = $("#isRememberUsername");
		
		// 记住用户名
		if(getCookie("adminUsername") != null) {
			$isRememberUsername.prop("checked", true);
			$username.val(getCookie("adminUsername"));
			$password.focus();
		} else {
			$isRememberUsername.prop("checked", false);
			$username.focus();
		}
		
		// 更换验证码
		$captchaImage.click( function() {
			$captchaImage.attr("src", "<%=base%>/admin/common/captcha.jhtml?captchaId=<%=captchaId%>&timestamp=" + (new Date()).valueOf());
		});
		
		// 表单验证、记住用户名
		$loginForm.submit( function() {
			if ($username.val() == "") {
				$.message("warn", "<%=SpringUtils.getMessage("admin.login.usernameRequired")%>");
				return false;
			}
			if ($password.val() == "") {
				$.message("warn", "<%=SpringUtils.getMessage("admin.login.passwordRequired")%>");
				return false;
			}
			if ($captcha.val() == "") {
				$.message("warn", "<%=SpringUtils.getMessage("admin.login.captchaRequired")%>");
				return false;
			}
			
			if ($isRememberUsername.prop("checked")) {
				addCookie("adminUsername", $username.val(), {expires: 7 * 24 * 60 * 60});
			} else {
				removeCookie("adminUsername");
			}
			
			var rsaKey = new RSAKey();
			rsaKey.setPublic(b64tohex("<%=modulus%>"), b64tohex("<%=exponent%>"));
			var enPassword = hex2b64(rsaKey.encrypt($password.val()));
			$enPassword.val(enPassword);
		});
		
		<%if (message != null) {%>
			$.message("error", "<%=SpringUtils.getMessage(message, setting.getAccountLockCount())%>");
		<%}%>
	});
</script>
<%} else {%>
<title>提示信息 - Powered By Finalist</title>
<meta http-equiv="expires" content="0" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta name="author" content="Finalist IT Group" />
<meta name="copyright" content="SHOP++" />
<link href="<%=base%>/resources/admin/css/common.css" rel="stylesheet" type="text/css" />
<link href="<%=base%>/resources/admin/css/login.css" rel="stylesheet" type="text/css" />
<%}%>
</head>
<body class="zh_CN">
	<div class="head" id="header">
		<div class="head_box">
			<div class="inner wrp">
				<div class="logo">
					<a href="<%=base%>" title=""><img
						src="<%=base%>/resources/travel/pc/images/logo.png" /></a>
				</div>
				<div class="account">
					<div class="account_meta account_faq">
						第一次使用风客平台？ <a target="__blank"
							href='<%=base %>/travel/pc/index/register.jhtml'>立即注册</a>
					</div>
				</div>
			</div>
		</div>
		<div class="banner">
			<div class="inner wrp">
				<div class="login_frame">
					<h3>登录</h3>
					<div class="login_err_panel" style="display: none;" id="err">
					</div>
					<form method="post" action="login.jsp" id="loginForm" class="form_login">
					   <input id="enPassword" name="enPassword" type="hidden">
						    <%if (ArrayUtils.contains(setting.getCaptchaTypes(), CaptchaType.adminLogin)) {%>
											<input type="hidden" name="captchaId" value="<%=captchaId%>" />
							<%}%>
						<div class="login_input_panel" id="js_mainContent">
								<div class="wxlogin_input">
								<label class="wx-col-sm-2 control-label" for="inputEmail3">用户名：</label>
								<div class="item-ifo">
									<input type="text" maxlength="20" class="text text_name" placeholder="用户名"
										name="username" id="username">
									<div class="i-ico i-name"></div>
								</div>
							</div>
							<div class="wxlogin_input">
								<label class="wx-col-sm-2 control-label" for="inputEmail3">密&nbsp;&nbsp;&nbsp;码：</label>
								<div class="item-ifo">
									<input type="password"
									placeholder="密码" autocomplete="off"   id="password" class="text text_name">
									<div class="i-pass i-ico "></div>
								</div>
							</div>
														 <%if (ArrayUtils.contains(setting.getCaptchaTypes(), CaptchaType.adminLogin)) {%>
							<div class="wxlogin_input">
								<label class="wx-col-sm-2 control-label" for="inputEmail3">验证码：</label>
								<div class="item-ifo">
									<input style="width: 112px !important; margin-right: 3px"  placeholder="验证码"  type="text" id="captcha" name="captcha"  class="text captcha text_name" maxlength="4" autocomplete="off"> <img
										id="captchaImage" class="captchaImage" src="<%=base%>/admin/common/captcha.jhtml?captchaId=<%=captchaId%>" title="<%=SpringUtils.getMessage("admin.captcha.imageTitle")%>">
								</div>
							</div>
							<%}%>
						</div>
						<div class="verifycode" style="display: none;" id="verifyDiv">
							<span class="frm_input_box"> <input class="frm_input text captcha text_name"
								type="text" id="verify" name="verify">
							</span> <img id="verifyImg" src="" /> <a href="javascript:;"
								id="verifyChange">换一张</a>
						</div>
					<!-- 	<div class="login_help_panel"> -->
							<!--selected-->
					<!--		<label class="frm_checkbox_label selected" for="rememberCheck"> -->
					<!--			<i class="icon_checkbox"></i> <input type="checkbox" -->
					<!--			class="frm_checkbox" id="rememberCheck"> 记住帐号 -->
					<!--		</label> -->
					<!--	</div> -->
						<div class="login_btn_panel">
								<input type="submit" id="loginBt" class="loginButton btn_login" value="<%=SpringUtils.getMessage("admin.login.login")%>" />
						</div>
						
						
					</form>
				</div>
				<dl class="qrcode_panel">
					<dt>
						<img
							src="<%=base%>/resources/travel/pc/images/qrcode.jpg">
					</dt>
					<dd>
						扫描并关注<br> 风客公众平台
					</dd>
				</dl>
			</div>
		</div>
	</div>
	<div class="foot" id="footer">
		<ul class="links ft">
			<li class="links_item no_extra"><a
				href="http://www.tencent.com/zh-cn/index.shtml" target="_blank">京ICP备14060464号-1 版权归风客所有</a></li>
		</ul>
	</div>
</body>

</html>
